#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <unordered_map>
// 回文子串：https://leetcode.cn/problems/palindromic-substrings/description/
using namespace std;
class Solution {
public:
    int countSubstrings(string s) {
        int n=s.size();
        vector<vector<bool>> dp(n,vector<bool>(n));
        int count=0;
        for(int i=n-1;i>=0;i--)
        {
            for(int j=i;j<n;j++)
            {
                if(s[i]==s[j])
                {
                    if((i==j)||(i+1==j))
                        dp[i][j]=true;  
                    else
                        dp[i][j]=dp[i+1][j-1];
                    count=dp[i][j]?count+1:count;
                }
            }
        }
        return count;
    }
};